/*
 * @lc app=leetcode.cn id=2064 lang=golang
 *
 * [2064] 分配给商店的最多商品的最小值
 */
package Solutions

// @lc code=start
func minimizedMaximum(n int, quantities []int) int {
	check := func(size int) bool {
		mn := 0
		for _, v := range quantities {
			mn += (v-1)/size + 1
		}
		return mn <= n
	}
	maxItem := -1
	for _, v := range quantities {
		if maxItem < v {
			maxItem = v
		}
	}
	l, r := 1, maxItem+1
	for l < r {
		mid := l + (r-l)/2
		if check(mid) {
			r = mid

		} else {
			l = mid + 1
		}
	}
	return l

}

// @lc code=end
